package com.example.vv.config;

import static java.lang.Boolean.TRUE;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;
import java.util.Objects;

/**
 * Bool转换器
 **/
public class BoolConverter implements Converter<Boolean> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return Boolean.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    //    @Override
    //    public Boolean convertToJavaData(ReadConverterContext<?> context) {
    //        Boolean v = context.getReadCellData().getBooleanValue();
    //        return v;
    //    }

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Boolean> context) {
        Boolean v = context.getValue();
        return Objects.equals(TRUE, v) ? new WriteCellData<>("是") : new WriteCellData<>("否");
    }
}
